package com.ma.dp.houserobber;

/**
 * @ClassName Solution213
 * @Author: mayongqiang
 * @DATE 2022/4/25 11:16
 * @Description:
 */
public class Solution213 {
    /*
    房子不是一排，而是围成了一个圈
     */
    public static void main(String[] args) {
        int[] nums = {1,2,3,1};
        System.out.println(rob(nums));
    }
    public static int rob(int[] nums) {
        int n = nums.length;
        return Math.max(dp(nums,0,n-2),dp(nums,1,n-1));
    }
    public static int dp(int[] nums,int start,int end) {

        int dp_i = 0, dp_i_1 = 0, dp_i_2 = 0;
        for (int i = end; i >= start; i--) {
            dp_i = Math.max(dp_i_1, nums[i] + dp_i_2);
            dp_i_2 = dp_i_1;
            dp_i_1 = dp_i;
        }
        return dp_i;
    }
}
